package com.xls.aclservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xls.base.model.SysLog;
import com.xls.aclservice.service.SysLogService;
import com.xls.aclservice.vo.SysLogQuery;
import com.xls.base.annotation.Log;
import com.xls.commonutils.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/acl/log")
@Api(value="日志接口")
@Slf4j
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;

    @PreAuthorize("hasAnyAuthority('system:sysLog:list')")
    @PostMapping("/list/{page}/{limit}")
    public Result<Page<SysLog>> list(@PathVariable Integer page, @PathVariable Integer limit,
                                     @RequestBody SysLogQuery sysLogQuery) {
        return Result.success(sysLogService.getSysLogPage(page, limit, sysLogQuery));
    }

    @PreAuthorize("hasAnyAuthority('system:sysLog:remove')")
    @Log(title = "日志管理", businessType = "删除")
    @DeleteMapping("/remove/{id}")
    public Result<SysLog> remove(@PathVariable String id) {
        sysLogService.removeById(id);
        return Result.success();
    }

    @PostMapping("/saveSysLog")
    public Result<SysLog> saveSysLog(@RequestBody SysLog sysLog) {
        sysLogService.save(sysLog);
        return Result.success();
    }

}
